import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const List= []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id:'@increment(1, 100)',
    time: +Mock.Random.date('T'),
    editTime:  +Mock.Random.date('T'),
    accounts:['1111','222','333'],
    account:'@first',
    name:'@first',
    members:'@int(0,50)',
    counts:'@int(0,50)',
    commissions:'@int(0,50)',
    last:'@int(0,50)',
    actual:'@int(0,50)',
    period:'@int(0,200)',
    adjust:'@int(0,200)',
    cost:'@int(0,50)',
    model:'@title(5, 10)',
    'type|1': [1,2],
    'status|1': [1,2],
    'auditStatus|1': _.map(consts.COMMISSION_AUDIT_STATUS,'value'),
    auditFirManager: '@first',
    auditSecManager: '@first',
    auditFirComment: Mock.Random.ctitle(0,20),
    auditSecComment: Mock.Random.ctitle(0,20),
    'auditFirStatus|1': [0,1,2],
    'auditSecStatus|1': [0,1,2],
    settlement:{
      betTimes: '@int(10,1000)',
      betTotal: '@int(10,1000)',
      bonusMax: '@int(10,1000)',
      bonusPercent: '@float(0,100,2)',
      waterMax: '@int(10,1000)',
      waterPercent: '@float(0,100,2)'
    },
    audit:[
      {name:'@first',comment:'@first'},
      {name:'@first',comment:'@first'},
    ],
    costApportion:[
      {
        name: '存款优惠',
        total: 100000.00,
        percent:10,
        summary:10000.00
      },
      {
        name: '红利',
        total: 100000.00,
        percent:10,
        summary:10000.00
      },
    ],
    gameSummary:[
      {
        name: 'IM体育',
        company: 100000.00,
        percent:10,
        summary:10000.00
      },
      {
        name: 'IM体育',
        company: 100000.00,
        percent:10,
        summary:10000.00
      },
    ],
    platformFee:{
      ag:{
        percent:'@float(0,100,2)',
        max:'@int(10,1000)',
      },
      pt:{
        percent:'@float(0,100,2)',
        max:'@int(10,1000)',
      },
    },
    games:[
      {
        game:'双鱼彩票',
        single:10,
        percent:50,
        'type|1': [1,2],
        stratified:[
          {
            max:100,
            percent:10,
            member:10,
          },
          {
            max:2220,
            percent:20,
            member:30,
          },
        ],
      },
      {
        game:'欧博真人',
        single:20,
        percent:30,
        'type|1': [1,2],
        stratified:[
          {
            max:100,
            percent:10,
            member:10,
          },
          {
            max:100,
            percent:10,
            member:10,
          },
        ],
      },
    ]


  }))
}

export default {
  [api.COMMISSION_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.COMMISSION_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    _.map(List,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
}
